<template>
  <div class="searchApp">
      <!-- 搜索和重置按鈕 -->
     <div class="search-reset-button">
        <el-row >
           <el-button 
           type="primary"
           icon="el-icon-search"
           size="medium"
            >{{ searchResetButton().search }}</el-button>
           <el-button 
            type="info"
            size="medium"
            icon="el-icon-edit"
            >{{ searchResetButton().reset }}</el-button>
        </el-row>
      </div>
    <el-row el-row type="flex" class="row-bg">
      <div v-for="(option, index) in searchArrayList" class="select-search" :key="index">
        <!-- 选择器 -->
        <div v-if="option.name === 'select'? true: false">
          <el-select v-model="option.value" :placeholder="option.placeholder">
            <el-option
              v-for="item in option.items"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="item.disabled"
            ></el-option>
          </el-select>
        </div>
        <!-- 输入框 -->
        <div v-if="option.name==='input'? true: false">
          <el-input :placeholder="option.placeholder" v-model="option.value" clearable></el-input>
        </div>
        <!-- 时间选择器 -->
        <div class="block" v-if="option.name==='dataPicker'? true: false">
          <span class="demonstration">{{ option.placeholder }}</span>
          <el-date-picker
            v-model="value5"
            type="datetimerange"
            :picker-options="pickerOptions"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            align="right"
          ></el-date-picker>
        </div>
      </div>
    </el-row>
  </div>
</template>

<script>
export default {
  props: {
    searchArrayList: {
      type: Array,
      required: true
    },
    searchResetButton: {
      type: Function,
      required: false,
      default: () => ({
      search: '搜索',
      reset: '重置'
    }),
    }
  },
  data() {
    return {
           pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        value4: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
        value5: ''
      };
  }
};
</script>
<style scoped>
.searchApp {
  box-sizing: border-box;
  position: relative;
  width: 100%;
  border: 1px solid #ccc;
  transition: box-shadow 0.3s ease;
}
/* 搜索按钮和重置按妞 */
.search-reset-button {
  margin-left: 10px;
  margin-right: 10px;
  border-bottom: 1px solid #ccc;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 10px;
}

.row-bg {
  display: flex;
  justify-content: start;
  align-items: center;
  flex-wrap: wrap;
}
.searchApp:hover {
  /* 悬停样式 */
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}
.row-bg .select-search {
  margin: 10px;
}
/* 时间选择器  start*/
.block .demonstration {
  margin-right: 10px;
}
/* 时间选择器  end*/

</style>>


